﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using CFM.DTO;
using CFM.DAL;
namespace CFM.API
{
    public class TableGroupAPI
    {
        private DataHelper _helper = null;
        public TableGroupAPI()
        {
            _helper = new DataHelper();
        }
        public List<TableGroup> GetAll()
        {
            string sql = "select * from [TableGroup]";
            SqlDataReader dr = _helper.ExcuteDataReader(sql, null);
            return _helper.MapDataReaderToObject<TableGroup>(dr);
        }
        public List<TableGroup> GetAllForSale()
        {
            string sql = "select * from [TableGroup]";
            SqlDataReader dr = _helper.ExcuteDataReader(sql, null);
            return _helper.MapDataReaderToObject<TableGroup>(dr);
        }
        public bool Create(TableGroup tablegroup)
        {
            string sql = "insert into TableGroup(TableGroupid,TableGroupname) values(@TableGroupid,@TableGroupname)";
            SqlParameter[] prs =
            {
                new SqlParameter("@TableGroupid",tablegroup.TableGroupId),
                new SqlParameter("@TableGroupname",tablegroup.TableGroupName)
            };
            return _helper.ExcuteNonQuery(sql, prs);
        }
        public bool Update(TableGroup tableGroup)
        {
            string sql = "update TableGroup set TableGroupname = @TableGroupname where TableGroupid = @TableGroupid";
            SqlParameter[] prs = 
            {
                new SqlParameter("@tableGroupID",tableGroup.TableGroupId),
                new SqlParameter("@tableGroupName",tableGroup.TableGroupName)
            };
            return _helper.ExcuteNonQuery(sql, prs);
        }


        public bool Delete(string tableGroupId)
        {
            string sql = "delete [TableGroup] where TableGroupId = @TableGroupId";
            SqlParameter[] prs = 
            {
                new SqlParameter("@TableGroupId",tableGroupId)
            };
            return _helper.ExcuteNonQuery(sql, prs);
        }
    }
}
